<?php

namespace App\Modules\Admin\Http\Controllers;

use App\Http\Controllers\BaseController;
use App\Services\VenueService;
use Illuminate\Http\Request;

class VenueController extends BaseController
{
    public function __construct(VenueService $venueService)
    {
        $this->venueService = $venueService;
    }

    public function index()
    {
        $data = $this->venueService->getAll();

        return $this->response->success($data);
    }

    public function show(Request $request)
    {
        $id = $request->input('id');
        $result = $this->venueService->getInfo($id);

        return $this->response->success($result);
    }

    public function store(Request $request)
    {
        $param = $this->validationParameter([
            'name|标题' => 'require',
            'desc|简介' => 'noRequire',
            'image|场馆图片' => 'require',
            'meet_cancel_set|取消设置' => 'require|number|default:0',
            'meet_status|状态' => 'require|number|default:1',
            'meet_max_join|预约最大人数' => 'noRequire|number',
        ]);

        $param['info']  = $request->input('info');

        $param['publisher_uid'] = $request->user()->admin_uid ?? null;

        $result = $this->venueService->add($param);

        return $this->response->success($result);
    }

    public function update(Request $request)
    {
        $id = $request->input('id');
        $param = [];
        $result = $this->venueService->update($param, $id);

        return $this->response->success($result);
    }

    public function destroy(Request $request)
    {
        $id = $request->input('id');
        $result = $this->venueService->delete($id);

        return $this->response->success($result);
    }
}
